//
// Created by YxMin on 2024/7/9.
//

#ifndef GAME_TEXTAREA_H
#define GAME_TEXTAREA_H
#include "Element.h"
#include <cstdio>
#include <easyx.h>
#include <font.h>
class TextArea: public Element{
private:
    char text[128];
    bool multiLine;
    COLORREF fontColor;
    FontStyle fontStyle;
public:
    TextArea(int uid, int x1, int y1, int x2, int y2,int radius = 0, char* text = nullptr,int height = 24,int width = 0,COLORREF fontColor = BLACK,bool multiLine = false)
            : Element(uid, x1, y1, x2,y2,radius, nullptr) {
        //init(uid,x1,y1,x2,y2,callback)
        //RegisterElement(this);
        this->fontColor = fontColor;
        this->multiLine = multiLine;
        strcpy(this->text ,text);
        fontStyle.height = height;
        fontStyle.width = width;
        fontStyle.color = fontColor;
        fontStyle.family = GetDefaultFont()->family;
    }
    ~TextArea() override = default;
    void showText() {
        SetFont(&fontStyle);
        drawtext(text,&area,DT_CENTER|DT_VCENTER|(multiLine ? 0 : DT_SINGLELINE));
        RecoverFont();
    }
    void draw() override {
        if(radius > 0) {
            roundrect(area.left,area.top,area.right,area.bottom,radius,radius);
        } else {
            rectangle(area.left,area.top,area.right,area.bottom);
        }
        settextcolor(fontColor);
        showText();
        settextcolor(BLACK);
    }
    char* getText() {
        return text;
    }
};


#endif //GAME_TEXTAREA_H
